package algorithm7.leetcode.每日一题.YEAR2023.month7;

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: permission
 * @Date: 2023/7/6 22:48
 * @Version: 1.0
 * @ClassName: DAY20230706_LC2178
 * @Description: LC2178. 拆分成最多数目的正偶数之和
 */
public class DAY20230706_LC2178 {

    public List<Long> maximumEvenSplit(long finalSum) {
        return handle1(finalSum);
    }

    // 贪心，直到拆分后的正整数已经取过
    private List<Long> handle1(long finalSum) {
        List<Long> res = new ArrayList<>();
        if (finalSum % 2 == 1) {
            return res;
        }
        for (long i = 2; i <= finalSum; i += 2) {
            finalSum -= i;
            res.add(i);
        }
        // 最后一个无法再拆分，加到最后一个上面
        res.set(res.size() - 1, res.get(res.size() - 1) + finalSum);
        return res;
    }

    @Test
    void t() {
        long finalSum = 12;
        List<Long> res = maximumEvenSplit(finalSum);
        System.out.println("res = " + res);
    }

}
